superstrict

import "Column.bmx"
import "Row.bmx"

type Table

	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getRow:Row(name:string)
	
		if (m_rowMap.contains(name)) ..
			return Row(m_rowMap.valueForKey(name));
		
		return null;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getColumn:Column(name:string)
	
		if (m_columnMap.contains(name)) ..
			return Column(m_columnMap.valueForKey(name));
		
		return null;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getValue:string(rname:string, cname:string)
	
		local r:Row = getRow(rname);
		
		if (not r or not cname) ..
			return null;
		
		local value:string = string(r.m_valueMap.valueForKey(cname));
		
		if (not value) ..
			return null;
		
		return value;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getInt:int(rname:string, cname:string)
	
		local value:string = getValue(rname, cname);
		
		if (not value) ..
			return 0;
		
		return value.toInt();
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getBool:short(rname:string, cname:string)
	
		local value:string = getValue(rname, cname);
		
		if (not value) ..
			return 0;
		
		select (value)
		
			case "true"
				value = "1";
			case "false"
				value = "0";
			case "null"
				value = "0";
			case "1"
			case "0"
			default
				value = "0";
		
		end select
		
		return value.toInt();
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getFloat:float(rname:string, cname:string)
	
		local value:string = getValue(rname, cname);
		
		if (not value) ..
			return 0;
		
		return value.toFloat();
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getDouble:double(rname:string, cname:string)
	
		local value:string = getValue(rname, cname);
		
		if (not value) ..
			return 0;
		
		return value.toDouble();
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getString:string(rname:string, cname:string)
	
		local value:string = getValue(rname, cname);
		return value;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method setInt(rname:string, cname:string, value:int)
	
		local r:Row = getRow(rname);
		local c:Column = getColumn(cname);
		
		if (not r or not c) ..
			return;
		
		r.m_valueMap.insert(cname, string.fromInt(value));
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method setBool(rname:string, cname:string, value:byte)
	
		local r:Row = getRow(rname);
		local c:Column = getColumn(cname);
		
		if (not r or not c) ..
			return;
		
		if (value > 1) ..
			value = 1;
		
		r.m_valueMap.insert(cname, string.fromInt(value));
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method setFloat(rname:string, cname:string, value:float)
	
		local r:Row = getRow(rname);
		local c:Column = getColumn(cname);
		
		if (not r or not c) ..
			return;
		
		r.m_valueMap.insert(cname, string.fromFloat(value));
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method setDouble(rname:string, cname:string, value:double)
	
		local r:Row = getRow(rname);
		local c:Column = getColumn(cname);
		
		if (not r or not c) ..
			return;
		
		r.m_valueMap.insert(cname, string.fromDouble(value));
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method setString(rname:string, cname:string, value:string)
	
		local r:Row = getRow(rname);
		local c:Column = getColumn(cname);
		
		if (not r or not c) ..
			return;
		
		r.m_valueMap.insert(cname, value);
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method pushColumn(col:Column)
	
		if (not col) ..
			return;
		
		m_columnList.addLast(col);
		m_columnMap.insert(col.m_name, col);
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method pushRow(rw:Row)
	
		if (not rw) ..
			return;
		
		m_rowList.addLast(rw);
		m_rowMap.insert(rw.m_name, rw);
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	method getName:string()
	
		return m_name;
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_name:string;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_columnList:TList = new TList;
	field m_columnMap:TMap = new TMap;
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// 
	'// -----------------------------------------------------------------------------------------------------------------
	field m_rowList:TList = new TList;
	field m_rowMap:TMap = new TMap;

end type
